package intensivecomp.mapred;

import org.apache.hadoop.io.DoubleWritable;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Reducer;

import java.io.IOException;

public class Reduce extends Reducer<Text,DoubleWritable,Text,DoubleWritable> {
    //result记录单词的频数
    private static DoubleWritable result = new DoubleWritable();
    public void reduce(Text key,Iterable<DoubleWritable> values,Context context) throws IOException,InterruptedException{
        double sum = 0;
        //对获取的<key,value-list>计算value的和
        for(DoubleWritable val:values){
            sum += val.get();
        }
        //将频数设置到result
        result.set(sum);
        //收集结果
        context.write(key, result);
    }
}
